package org.dromara.quickswing.ui.app;

import org.dromara.quickswing.QSApplication;

import javax.swing.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Jin
 */
public class QSMenuBar<T extends QSApplication> extends JMenuBar {

    private final transient T app;
    private Map<String, JMenu> namedMenus;
    public QSMenuBar(T app) {
        this.app = app;
    }

    public T getApp() {
        return app;
    }
    public void registerMenuByName(String name, JMenu menu) {
        if (name==null) {
            throw new NullPointerException("menu name cannot be null");
        }
        if (namedMenus==null) {
            namedMenus = new HashMap<>();
        }
        namedMenus.put(name, menu);
    }
    public JMenu getMenuByName(String name) {
        return namedMenus!=null ? namedMenus.get(name) : null;
    }

}